﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Src="../Shared/Header.ascx" TagName="Header" TagPrefix="uc1" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>功能管理</title>
    <uc1:Header ID="Header1" runat="server" />
    <script type="text/javascript" language="javascript">
        $(function () {

            $('#grid').datagrid({
                iconCls: 'icon-ok',
                nowrap: false,                      //数据是否显示在一行里
                striped: true,                      //奇偶行使用不同背景色
                url: '/ActionPermission/LoadAllWithPage/',  //从远程站点请求数据的 URL
                fitColumns: true,                   //适应表格的宽度并且防止水平滚动
                fit: true,
                idField: 'Id',                      //标识字段
                remoteSort: false,                  //定义是否从服务器给数据排序
                singleSelect: true,                //是否允许选中一行
                pagination: true,                  //分页
                rownumbers: true,                   //行号
                pageSize: 20,
//                frozenColumns: [[
//	                { field: 'Id', checkbox: true}  //和列的特性一样，但是这些列将被冻结在左边
//				]],
                columns: [[
                     { field: 'ActionName', title: '功能名称', width: 80 }                   
                    , { field: 'ControllerName', title: '模块', width: 80 }
                    , { field: 'Description', title: '描述', width: 80 }
                    , { field: 'CreateTime', title: '创建时间', width: 80 }
                    , { field: 'ActionID', title: '权限编号', hidden: true }
                ]]
            });

        });


        function submit() {

            $('#form').form('submit', {
                onSubmit: function () {
                    return $(this).form('validate');
                },
                success: function (msg) {
                    var msg1 = eval('(' + msg + ')');
                    if (msg1.IsSuccess) {
                        $.messager.alert('提示', "保存成功", 'info', function () {
                            //                            $('#win').dialog('close');
                            $('#grid').datagrid('reload');
                        });
                    }
                    else {
                        $.messager.alert('提示', msg1.Message, "error");
                    }
                },
                error: function () {
                    $.messager.alert('错误', '保存失败！', "error");
                }
            });
        }

        function add() {
            $('#win').dialog({
                title: '新增功能',
                iconCls: 'icon-add',
                width: 400,
                height: 204,
                closed: false,
                cache: false,
                href: '/ActionPermission/Add/',
                modal: true,
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: submit
                }, {
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        $('#win').dialog('close');
                    }
                }],
                onLoad: function () {
                    $("#ActionName").combogrid({
                        panelWidth: 520,
                        panelHeight: 308,
                        idField: 'ActionName',
                        textField: 'ActionName',
                        url: '/ActionPermission/LoadAllByAssembly/',
                        singleSelect: true,                //是否允许选中一行
                        pagination: true,                  //分页
                        rownumbers: true,                   //行号
                        pageSize: 10,                        //每页记录数
                        pageList: [10],             //每页记录数列表
                        columns: [[
					                    { field: 'ActionName', title: '功能名称', width: 150 }
                                        , { field: 'ControllerName', title: '模块', width: 139 }
                                        , { field: 'Description', title: '描述', width: 200 }
                                        , { field: 'ActionID', title: '权限编号', hidden:true }
				                    ]],
                        onSelect: function (rowIndex, rowData) {
                            //alert(rowIndex + "\n" + rowData);
                            $("#ControllerName").val(rowData.ControllerName);
                            $("#ControllerName1").val(rowData.ControllerName);
                            $("#Description").val(rowData.Description);
                            $("#ActionID").val(rowData.ActionID);
                        },
                        delay: 500,
                        mode: 'remote',
                        onChange: function (newValue, oldValue) {
                            $("#ControllerName").val("");
                            $("#ControllerName1").val("");
                            $("#Description").val("");                            
                        }
                    });
                }
            });
         }

         function edit() {
             var row = $('#grid').datagrid('getSelected');
             if (row) {

                 $('#win').dialog({
                     title: '修改功能',
                     iconCls: 'icon-save',
                     width: 400,
                     height: 204,
                     closed: false,
                     cache: false,
                     href: '/ActionPermission/Edit/' + row.Id,
                     modal: true,
                     buttons: [{
                         text: '提交',
                         iconCls: 'icon-ok',
                         handler: submit
                     }, {
                         text: '取消',
                         iconCls: 'icon-cancel',
                         handler: function () {
                             $('#win').dialog('close');
                         }
                     }]
                 });
             } else {
                 $.messager.alert('提示', '请选择要修改的数据');
                 return;
             }
        }

        function del() {
            var rows = $('#grid').datagrid('getSelections');
            if (!rows || rows.length == 0) {
                $.messager.alert('提示', '请选择要删除的数据');
                return;
            }
            var parm;
            $.each(rows, function (i, n) {
                if (i == 0) {
                    parm = "idList=" + n.Id;
                }
                else {
                    parm += "&idList=" + n.Id;
                }
            });
            $.messager.confirm('提示', '是否删除这些数据?', function (r) {
                if (!r) {
                    return;
                }

                $.ajax({
                    type: "POST",
                    url: "/ActionPermission/Delete/",
                    data: parm,
                    success: function (msg) {
                        if (msg.IsSuccess != null) {
                            if (msg.IsSuccess) {
                                $.messager.alert('提示', '删除成功！', "info", function () {
                                    $('#grid').datagrid("reload");
                                });
                            }
                            else {
                                $.messager.alert('提示', msg.Message, "error");
                            }
                        } 
                        else {
                            eval(msg);
                        }
                    },
                    error: function () {
                        $.messager.alert('错误', '删除失败！', "error");
                    }
                });
            });
        }
    </script>
</head>
<body class="easyui-layout">
    <div region="center" style="padding: 5px;" border="false">
        <table id="grid" toolbar="#toolbar">
        </table>
        <div id="toolbar" style="padding: 2px; height: auto">
            <a id="btnAdd" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-add" plain="true" onclick="add()">添加</a>
            <a id="btnUpdate" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-edit" plain="true" onclick="edit()">修改</a>
            <a id="btnDelete" class="easyui-linkbutton" href="javascript:void(0)" iconcls="icon-remove" plain="true" onclick="del()">删除</a>
        </div>
    </div>
    <div id="win" />
</body>
</html>
